object ConstructorDemo01 {
  def main(args: Array[String]): Unit = {
    //val person = new PersonA("tom",99)//不会⾛主构造器
    val person = new PersonA("tom")
    println(person)
    val a1 = new A
    val a2 = new A()
  }
}

/**
 * 构造器的快速⼊⻔
 * 创建Person对象的同时初始化对象的age属性值和name属性值
 */
class PersonA(inName: String, inAge: Int) {
  var name: String = inName
  var age: Int = inAge
  age += 10
  println("age=" + age)

  def this(name: String) {
    //辅助构造器，必须在第⼀⾏显式调⽤主构造器(可以是直接，也可以是间接)
    this("jack", 10)
    println("------------------")
    //this
    this.name = name //重新赋值
  }

  //重写了toString，便于输出对象的信息
  override def toString: String = {
    "name=" + this.name + "\t age" + this.age
  }
}

class A() {
}
